#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
using namespace std;
class Solution {
public:
    vector<int> replaceElements(vector<int>& arr)
    {
        vector<int> ret = arr;
        int max = ret[ret.size() - 1];
        ret[ret.size() - 1] = -1;
        for (int i = ret.size() - 2;i >= 0;i--)
        {
            int tmp = ret[i];
            ret[i] = max;
            if (tmp > max) max = tmp;
        }
        return ret;
    }
};